//
//  CourseRecordV.m
//  HTT
//  课程想也vc 课程基本信息view
//  Created by admin on 15/12/1.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "CourseRecordV.h"

#import "CourseRecordDetailModel.h"
#define kCourseRecordVPadding 10
#define kMaxWidth (ScreenWidth - 20)/2.0
@interface CourseRecordV()
@property (nonatomic, retain)CourseRecordDetailModel *courseDetail;

@property (nonatomic, strong) UIImageView *studentImage;
@property (nonatomic, strong) UIImageView *flagImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *courseLabel;
@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic ,strong) UILabel *addressLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *startTimeLabel;
@property (nonatomic, strong) UILabel *endTimeLabel;
@end
@implementation CourseRecordV
- (instancetype)init{
    self = [super init];
    if (self) {
        [self _initView];
    }
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)_initView{
    [self setBackgroundColor:[UIColor whiteColor]];
    UILabel *titleLabel = [self getNormolLabel];
    titleLabel.font = [UIFont systemFontOfSize:20];
    titleLabel.text = @"课程详情";
    titleLabel.textAlignment = _TEXT_ALIGN_LEFT;
    [titleLabel setFrame:CGRectMake(10, 5, ScreenWidth / 2.0 - 20, 30)];
    [self addSubview:titleLabel];
    
    UIImageView *imageLine = [[UIImageView alloc] initWithFrame:CGRectMake(10, 39, ScreenWidth - 20, 1)];
    [imageLine setBackgroundColor:RGBCOLOR(240, 240, 240, 1)];
    [self addSubview:imageLine];
    
    _flagImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 10 - 60, 10, 50, 20)];
    [self addSubview:_flagImage];
    
    _studentImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 10 - 50, 40 + kCourseRecordVPadding, 50, 50)];
    [self addSubview:_studentImage];
    
    _nameLabel = [self getNormolLabel];
    [self addSubview:_nameLabel];
    
    _courseLabel = [self getNormolLabel];
    [self addSubview:_courseLabel];
    
    _countLabel = [self getNormolLabel];
    [self addSubview:_countLabel];
    
    _addressLabel = [self getNormolLabel];
    [self addSubview:_addressLabel];
    
    _dateLabel = [self getNormolLabel];
    [self addSubview:_dateLabel];
    
    _startTimeLabel = [self getNormolLabel];
    [self addSubview:_startTimeLabel];
    
    _endTimeLabel = [self getNormolLabel];
    [self addSubview:_endTimeLabel];
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
}
- (void)setViewData:(id)viewData{
    _courseDetail = (CourseRecordDetailModel *)viewData;
    
    
    [_studentImage setNormalImageUrl:_courseDetail.teacherPhoto anplaceholder:@"m_user_y_h"];
    
    _nameLabel.text = [NSString stringWithFormat:@"教师: %@",_courseDetail.teacherName];
    CGSize nameSize = [_nameLabel.text textSizeWithFont:_nameLabel.font constrainedSize:CGSizeMake(kMaxWidth-10, 100)];
    [_nameLabel setFrame:CGRectMake(ScreenWidth - 10 - nameSize.width, CGRectGetMaxY(_studentImage.frame) + 5, nameSize.width, nameSize.height)];
    
    [_studentImage setCenter:CGPointMake(_nameLabel.center.x, _studentImage.center.y)];
    
    _courseLabel.text = [NSString stringWithFormat:@"学科: %@ %@",_courseDetail.courseName,_courseDetail.crId];
    CGSize courseSize = [_courseLabel.text textSizeWithFont:_courseLabel.font constrainedSize:CGSizeMake(kMaxWidth, 100)];
    [_courseLabel setFrame:CGRectMake(10, 40 + kCourseRecordVPadding, courseSize.width, courseSize.height)];
    
    _countLabel.text = [NSString stringWithFormat:@"次数: %@/%@",_courseDetail.cgRemainCount,_courseDetail.cgCount];
     courseSize = [_countLabel.text textSizeWithFont:_countLabel.font constrainedSize:CGSizeMake(kMaxWidth, 100)];
    [_countLabel setFrame:CGRectMake(10, CGRectGetMaxY(_courseLabel.frame) + kCourseRecordVPadding, courseSize.width, courseSize.height)];
    
    
    
    _dateLabel.text = [NSString stringWithFormat:@"日期: %@",_courseDetail.cgcDate];
    courseSize = [_dateLabel.text textSizeWithFont:_dateLabel.font constrainedSize:CGSizeMake(kMaxWidth, 100)];
    [_dateLabel setFrame:CGRectMake(10, CGRectGetMaxY(_countLabel.frame) + kCourseRecordVPadding, courseSize.width, courseSize.height)];
    
    _startTimeLabel.text = [NSString stringWithFormat:@"开始时间: %@",_courseDetail.cgcStartTime];
    if ([_courseDetail.cgcStatus integerValue] >= 1) {
        _startTimeLabel.text = [NSString stringWithFormat:@"开始时间: %@",_courseDetail.crStartTime];
    }
    courseSize = [_startTimeLabel.text textSizeWithFont:_startTimeLabel.font constrainedSize:CGSizeMake(kMaxWidth, 100)];
    [_startTimeLabel setFrame:CGRectMake(10, CGRectGetMaxY(_dateLabel.frame) + kCourseRecordVPadding, courseSize.width, courseSize.height)];
    
    _endTimeLabel.text = [NSString stringWithFormat:@"结束时间: %@",_courseDetail.cgcStopTime];
    if ([_courseDetail.cgcStatus integerValue] >= 1) {
        _endTimeLabel.text = [NSString stringWithFormat:@"结束时间: %@",_courseDetail.crEndTime];
    }
    
    courseSize = [_endTimeLabel.text textSizeWithFont:_endTimeLabel.font constrainedSize:CGSizeMake(kMaxWidth, 100)];
    [_endTimeLabel setFrame:CGRectMake(10, CGRectGetMaxY(_startTimeLabel.frame) + kCourseRecordVPadding, courseSize.width, courseSize.height)];
    
    _addressLabel.text = [NSString stringWithFormat:@"地点: %@",_courseDetail.cgAddress];
    courseSize = [_addressLabel.text textSizeWithFont:_addressLabel.font constrainedSize:CGSizeMake(ScreenWidth - 20, 100)];
    [_addressLabel setFrame:CGRectMake(10, CGRectGetMaxY(_endTimeLabel.frame) + kCourseRecordVPadding, courseSize.width, courseSize.height)];
    
    [_flagImage setImage:[self getFalgImage]];
    self.frame = CGRectMake(0, 0, ScreenWidth, CGRectGetMaxY(_addressLabel.frame) + 10);
    
    
}
- (UIImage *)getFalgImage{
    NSInteger returnFlag = 0;
    NSInteger flag = [_courseDetail.cgcStatus integerValue];
    if (flag == 1 || flag == 0) {
        //还没有开始上课
        returnFlag = 1;
    }else{
        if (returnFlag == 1) {
            
        }else{
            if ([_courseDetail.crAccess integerValue] == 0) {
                returnFlag = 2;//为评价
            }else{
                returnFlag = 3;//已完成
            }
        }
    }
    if (returnFlag == 1) {
        return [UIImage imageNamed:@"weiwancheng"];
    }else if (returnFlag == 2){
        return [UIImage imageNamed:@"weipingjia"];
    }else if (returnFlag == 3){
        return [UIImage imageNamed:@"yiwancheng"];
    }else{
        return nil;
    }
}
-(UILabel *)getNormolLabel{
    UILabel *label = [[UILabel alloc] init];
    label.textAlignment = _TEXT_ALIGN_CENTER;
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = RGBCOLOR(0, 0, 0, 0.7);
    label.numberOfLines = 0;
    return label;
}
@end
